FROM lukemathwalker/cargo-chef:latest-rust-slim-bookworm as chef
WORKDIR /build

FROM chef as planner
COPY . .
RUN cargo chef prepare  --recipe-path recipe.json

FROM chef as builder
COPY .cargo/config $CARGO_HOME
COPY --from=planner /build/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release --bin app

FROM frolvlad/alpine-glibc AS runtime
WORKDIR /app
COPY --from=builder /build/target/release/app /usr/bin/app
ENTRYPOINT ["app"]